fix(decimal): use minimal byte length for negative powers of two - #3746
Merged
kevinjqliu merged 3 commits intoAug 20, 2026
Merged
Conversation
kevinjqliu
approved these changes
Aug 20, 2026
kevinjqliu
left a comment
Contributor
There was a problem hiding this comment.
LGTM thanks for catching and fixing this.
i pushed up a commit to rephrase some of the comments
Contributor
|
Thanks for the pr @vishnuprakaz |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reopening #3523, which was auto-closed for inactivity. Rebased on latest
main; the bug is still present.Closes #3522
Rationale for this change
bytes_requiredshould return the minimum number of bytes for a value, but it returns one byte too many for negatives like -128 and -32768.This matters because the decimal bucket transform hashes those bytes. The extra byte changes the hash, so PyIceberg can put a value in a different bucket than Spark/Java. For example,
Decimal("-1.28")goes to bucket 12 in PyIceberg but bucket 13 everywhere else.The fix computes the length from
(value + 1)for negative values, which gives the true minimum and matches the Iceberg spec.Are these changes tested?
Yes. Added tests for the -128 / -32768 / -8388608 boundary cases (where the old code was wrong) plus positive/negative controls. Lint and the decimal/conversion/transform tests pass.
Are there any user-facing changes?
Yes. For decimal values like -1.28, the computed bucket changes (e.g. 12 → 13) so it now matches other Iceberg engines.